package superAdmin;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvFileSource;
import org.junit.jupiter.params.provider.CsvSource;
import org.openqa.selenium.By;

import java.util.concurrent.TimeUnit;

import static java.lang.Thread.sleep;
/*
    任务书的增删查
 */
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class AddTaskFile extends InitAdmin{
    @ParameterizedTest
    @CsvFileSource(resources = "../superadminLogin.csv")
    @Order(1)
    void login(String name,String password,String loginURL,String toURL) throws InterruptedException {

        //获取登录页
        webDriver.get(loginURL);
        webDriver.manage().window().maximize();
        webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.DAYS);
        System.out.println("username:"+name);
        System.out.println("password:"+password);
        //输入账号密码
        webDriver.findElement(By.cssSelector("#login > div.logIn-inner > div.right-con.fr > div > div.login-form > form > div:nth-child(1) > div > div > input")).sendKeys(name);
        webDriver.findElement(By.cssSelector("#login > div.logIn-inner > div.right-con.fr > div > div.login-form > form > div:nth-child(2) > div > div > input")).sendKeys(password);
        //点击登录
        webDriver.findElement(By.cssSelector("#login > div.logIn-inner > div.right-con.fr > div > div.login-form > form > div:nth-child(3) > div > button")).click();
        webDriver.manage().window().maximize();
        sleep(3000);

        String curUrl = webDriver.getCurrentUrl();
        Assertions.assertEquals(toURL,curUrl);
        sleep(3000);

    }
    @ParameterizedTest
    @CsvSource("C:\\Users\\admin\\Desktop\\资源平台测试数据\\svgz\\建施04.svgz")
    @Order(2)
    void addTask(String file) throws InterruptedException {
        //点击 资源管理
        webDriver.findElement(By.cssSelector("#admin > div.main > div.wa.container.clearfix > div.left-menu > ul > li:nth-child(3) > ul > li")).click();
        //点击第一个 一级目录
        webDriver.findElement(By.cssSelector("#admin > div.main > div.wa.container.clearfix > div.right-content > div > div.main-inner > div.source-table.common-table > table > tbody > tr:nth-child(1) > td:nth-child(2) > em"))
                .click();
        //点击步骤1
        webDriver.findElement(By.cssSelector("#admin > div.main > div.wa.container.clearfix > div.right-content > div > div.main-inner > div:nth-child(2) > table > tbody > tr:nth-child(1) > td:nth-child(2) > em"))
                .click();
        //点击  任务书
        webDriver.findElement(By.cssSelector("#admin > div.main > div.wa.container.clearfix > div.right-content > div > div.main-inner > div:nth-child(2) > table > tbody > tr:nth-child(1) > td:nth-child(2) > em"))
                .click();
        //点击上传文件
        webDriver.findElement(By.cssSelector("#admin > div.main > div.wa.container.clearfix > div.right-content > div > div.tit.clearfix > div.fr.tit-right > button:nth-child(1) > span"))
                .click();
        //选择文件
        webDriver.findElement(By.cssSelector("#uploadFile > div > div > div.el-dialog__body > div > div > div.btns > input")).sendKeys(file);
        sleep(3000);
        //点击开始上传
        webDriver.findElement(By.cssSelector("#uploadListAction")).click();
        webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.DAYS);
        sleep(3000);
        //获取当前上传的状态
        String status = webDriver.findElement(By.xpath("/html/body/div[1]/div[2]/div[7]/div/div/div[2]/div/div/div[2]/table/tbody/tr/td[4]")).getText();
        System.out.println("上传状态是:"+status);
        Assertions.assertEquals("上传成功",status);
        //关闭上传 弹窗
        webDriver.findElement(By.cssSelector("#uploadFile > div > div > div.el-dialog__header > button > i")).click();
        sleep(3000);

    }
    @Test
    @Order(3)
    void searchTask() throws InterruptedException {
       String num =  webDriver.findElement(By.cssSelector("#page > div > div > span")).getText();
        System.out.println("num："+num);
       Assertions.assertEquals("共 1 条",num);
       //点击预览
       webDriver.findElement(By.cssSelector("#admin > div.main > div.wa.container.clearfix > div.right-content > div > div.main-inner > div:nth-child(2) > table > tbody > tr > td:nth-child(2) > em")).click();
       sleep(3000);
       //关闭预览
       webDriver.findElement(By.xpath("//*[@id=\"layui-layer100001\"]/span[1]/a[3]")).click();
    }
    @Test
    @Order(4)
    void deleteTask() throws InterruptedException {
        //删除 上传的文件
        webDriver.findElement(By.cssSelector("#admin > div.main > div.wa.container.clearfix > div.right-content > div > div.main-inner > div:nth-child(2) > table > tbody > tr > td:nth-child(7) > a"))
                .click();
        //确定删除
        webDriver.findElement(By.cssSelector("body > div.el-message-box__wrapper > div > div.el-message-box__btns > button.el-button.el-button--default.el-button--small.el-button--primary.confirm-btn > span"))
                .click();
        sleep(3000);
    }
}
